home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
rwvector.lha
/
RWVector2.1
/
src
/
xgematio.cc
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-18
|
3KB
|
121 lines
/*
* Definitions for <A>GEMatrix I/O
*
* Copyright (C) 1988, 1989.
*
* Dr. Thomas Keffer
* Rogue Wave Associates
* P.O. Box 85341
* Seattle WA 98145-1341
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and
* without fee is hereby granted, provided that the
* above copyright notice appear in all copies and that
* both that copyright notice and this permission notice
* appear in supporting documentation.
*
* This software is provided "as is" without any
* expressed or implied warranty.
*
*
* @(#)xgematio.cc 2.1 8/18/89
*/
#define NO_VECTOR_MATHFUN
#include "rw/<A>GEMatrix.h"
#include <stream.h>
ostream&
operator<<(ostream& s, const <A>GEMatrix& m)
{
for (register int i=0; i< m.rows(); i++){
for (register int j = 0; j < m.cols(); j++) s << m(i,j) << " ";
s << NL;
}
return s;
}
void
<A>GEMatrix::assertRowRange(int i)
{
if(i < 0 || i >= nrows){
char msg[120];
sprintf(msg, "Row index (%d) out of range [0->%d].", i, nrows-1);
RWnote("<A>GEMatrix::assertRowRange()", msg);
RWerror(DEFAULT);
}
}
void
<A>GEMatrix::assertColRange(int j)
{
if(j < 0 || j >= ncols){
char msg[120];
sprintf(msg, "Column index (%d) out of range [0->%d].", j, ncols-1);
RWnote("<A>GEMatrix::assertColRange()", msg);
RWerror(DEFAULT);
}
}
void
<A>GEMatrix::assertRowCol(const <A>GEMatrix& m)
{
if(m.nrows != nrows || m.ncols != ncols){
char msg[120];
sprintf(msg, "Rows/Columns do not match: (%d, %d) versus (%d, %d)",
nrows, ncols, m.nrows, m.ncols);
RWnote("<A>GEMatrix::assertRowCol()", msg);
RWerror(DEFAULT);
}
}
void
<A>GEMatrix::assertLength(const <T>Vec& v)
{
if(nrows*ncols != v.length()){
char msg[120];
sprintf(msg, "Vector length (%d) does not match rows and columns (%d, %d)",
v.length(), nrows, ncols);
RWnote("<A>GEMatrix::assertLength()", msg);
RWerror(DEFAULT);
}
}
void
<A>GEMatrix::assertSquare()
{
if(nrows != ncols){
char msg[120];
sprintf(msg, "Matrix (%d by %d) is not square", nrows, ncols);
RWnote("<A>GEMatrix::assertSquare()", msg);
RWerror(DEFAULT);
}
}
void
<A>GEMatrix::assertProduct(const <A>GEMatrix& m)
{
if(ncols!=m.nrows){
char msg[120];
sprintf(msg, "Inner product not possible between (%d by %d) and (%d by %d)",
nrows, ncols, m.nrows, m.ncols);
RWnote("<A>GEMatrix::assertProduct()", msg);
RWerror(DEFAULT);
}
}
void
<A>GEMatrix::assertProduct(const <T>Vec& v)
{
if(ncols!=v.length()){
char msg[120];
sprintf(msg, "Inner product not possible between matrix %d by %d and vector %d points long",
nrows, ncols, v.length());
RWnote("<A>GEMatrix::assertProduct()", msg);
RWerror(DEFAULT);
}
}